package com.kgc.app.service.impl;

import com.kgc.app.mapper.AppCategoryMapper;
import com.kgc.app.pojo.AppCategory;
import com.kgc.app.pojo.AppCategoryExample;
import com.kgc.app.service.AppCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AppCategoryServiceImpl implements AppCategoryService {

    @Autowired
    private AppCategoryMapper appCategoryMapper;

    @Override
    public List<AppCategory> selectCategoryByParentId(Long parentId) {

        //1.创建条件类
        AppCategoryExample example = new AppCategoryExample();
        AppCategoryExample.Criteria criteria = example.createCriteria();

        //2.拼接查询条件
        if (null == parentId ){
            criteria.andParentIdIsNull();
        }else {
            criteria.andParentIdEqualTo(parentId);
        }

        List<AppCategory> appCategories = appCategoryMapper.selectByExample(example);

        return appCategories;
    }
}
